<template>
  <div class="visitor-alreadyVisited">
    <div class="search-group">
      <div class="input-wrap">
        <div class="label">手机串码:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model.trim="queryParam.imei" placeholder="请填写" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">手机型号:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model.trim="queryParam.phoneModule" placeholder="请填写" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">所属人姓名:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model.trim="queryParam.name" placeholder="请填写" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">联系电话:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model.trim="queryParam.mobile" placeholder="请填写" />
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">身份证号:</div>
        <div class="input-item">
          <a-input allowClear :maxLength="30" clearable v-model.trim="queryParam.idCard" placeholder="请填写" />
        </div>
      </div>

      <div class="input-wrap">
        <div class="label">备案时间:</div>
        <div class="time-item">
          <start-end-time
            :times="times"
            :showTime="{ format: 'HH:mm:ss' }"
            format="YYYY-MM-DD HH:mm:ss"
            @timeChange="timeChange"
            :resetTime="resetTime"
          ></start-end-time>
        </div>
      </div>
      <div class="input-wrap">
        <div class="label">状态:</div>
        <div class="input-item">
          <a-select v-model.trim="queryParam.status" placeholder="请选择" show-search allowClear>
            <a-select-option :value="0"> 已备案 </a-select-option>
            <a-select-option :value="1"> 已挂失 </a-select-option>
          </a-select>
        </div>
      </div>
      <div class="btn-wrap">
        <a-button class="searchBtn" @click="searchQuery()" type="primary"> 搜索 </a-button>
        <a-button class="resetBtn" @click="searchReset()" type="primary"> 重置 </a-button>
      </div>
    </div>

    <div>
      <a-table
        ref="table"
        rowKey="id"
        class="tableList"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <template slot="action" slot-scope="records">
          <span class="operation deatil-color" @click="handleDetail(records)">详情</span>
        </template>
      </a-table>
    </div>
    <RentDetail ref="rentDetailRef" />
  </div>
</template>

<script>
import startEndTime from '@/components/startEndTime'
import { JeecgListMixinNew } from '@/mixins/JeecgListMixinNew'
import { getCommunityList, getDictItemsFromCache, getSubordinateList } from '../../../api/api'
import RentDetail from './modules/phoneDetail.vue'
import { handleSelectChange } from '../../../utils/util'
export default {
  name: 'room',
  components: { startEndTime, RentDetail },
  mixins: [JeecgListMixinNew],
  props: {
    idCode: {
      type: String,
      default: '',
    },
    villageList: {
      type: Array,
      default: () => [],
    },
  },
  watch: {
    idCode(newVal) {
      this.extendParams.policeAgencyId = newVal
    },
  },
  data() {
    return {
      url: {
        list: '/registered/phone/page',
      },
      publicVisible: false,
      columns: [
        {
          title: '序号',
          align: 'center',
          width: 100,
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '手机串码(IMEI)一',
          dataIndex: 'imeiOne',
          ellipsis: true,
          width: 300,
          align: 'center',
        },
        {
          title: '手机串码(IMEI)二',
          dataIndex: 'imeiTwo',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '手机型号',
          dataIndex: 'phoneModule',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '所属人',
          dataIndex: 'belongingPersonName',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '联系电话',
          dataIndex: 'belongingPersonMobile',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '身份证号',
          dataIndex: 'belongingPersonIdcard',
          ellipsis: true,
          align: 'center',
        },
        {
          title: '备案时间',
          dataIndex: 'createTime',
          ellipsis: true,
          align: 'center',
          width: 200,
        },
        {
          title: '状态',
          dataIndex: 'status',
          ellipsis: true,
          align: 'center',
          width: 200,
          customRender: (t) => {
            return t == 0 ? '已备案' : '已挂失'
          },
        },
        {
          title: '操作',
          scopedSlots: { customRender: 'action' },
          ellipsis: true,
          align: 'center',
          width: 100,
        },
      ],
      project_company_type: [],
      times: {},
      buildingList: [],
      unitList: [],
      floorList: [],
      roomList: [],
      queryParam: this.initQueryParams(),
      flagTypeList: [],
      extendParams: {},
    }
  },
  mounted() {
    this.flagTypeList = getDictItemsFromCache('flag_type')
    this.initPage()
  },
  methods: {
    initQueryParams() {
      return {
        xQfDzbm: undefined,
        jzfDzbm: undefined,
        dyfDzbm: undefined,
        lcfDzbm: undefined,
        fjfDzbm: undefined,
        headName: '',
        idCard: '',
      }
    },
    searchReset() {
      this.queryParam = this.initQueryParams()
      this.buildingList = []
      this.unitList = []
      this.floorList = []
      this.roomList = []
      if (this.resetTime !== undefined) {
        this.resetTime = true
      }
      this.loadData(1)
    },
    handleDetail(records) {
      this.$refs.rentDetailRef.show(records)
    },
    handleSelectChange,
    filterOption(input, option) {
      return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0
    },
    searchQuery() {
      const { startTime, endTime } = this.queryParam
      if ((startTime && !endTime) || (!startTime && endTime)) {
        this.$message.error('开始时间结束时间必须同时选择')
        return
      }
      this.loadData(1)
    },
    timeChange(v, index) {
      if (index == 1) {
        this.queryParam.startTime = this.$moment(v).valueOf()
        if (v == null) {
          this.queryParam.startTime = null
        }
      } else {
        this.queryParam.endTime = this.$moment(v).valueOf()
        if (v == null) {
          this.queryParam.endTime = null
        }
      }
    },
    async initPage() {
      try {
        console.log(res)
      } catch (error) {
      } finally {
      }
    },
  },
}
</script>
